package common;

import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lileilei
 * @Description
 * @create 2020-06-20 17:04
 */
public class JsonParam {
    private Map<String, Object> stringtomap(String string) {
        Map<String, Object> reslutmap = new HashMap<>();
        Gson gson = new Gson();
        JsonBean jsonBean = gson.fromJson(string, JsonBean.class);
        Integer code = jsonBean.getCode();
        String msg = jsonBean.getMsg();
        Data data = jsonBean.getData();
        List<Result> resultList = data.getResult();
        List<Map<String, Object>> mapList = new ArrayList<>();
        for (Result result : resultList) {
            Map<String, Object> map = new HashMap<>();
            map.put("projectid", result.getProjectid());
            map.put("projectname", result.getProjectname());
            map.put("testid", result.getTestid());
            map.put("testurl", result.getTesturl());
            map.put("name", result.getName());
            map.put("id", result.getId());
            List<IntefaceLinkDaos> intefaceDetailParamesVos = result.getIntefaceLinkDaos();
            List<CommonParam> commonParamList = result.getCommonParamedetaiVoList();
            List<Map<String, Object>> intefaceDetailDaosVoList = new ArrayList<>();
            if (!intefaceDetailParamesVos.isEmpty()) {
                for (IntefaceLinkDaos intefaceLinkDaos : intefaceDetailParamesVos) {
                    Map<String, Object> objectMap = new HashMap<>();
                    objectMap.put("intefaceid", intefaceLinkDaos.getIntefaceid());
                    objectMap.put("intefaceurl", intefaceLinkDaos.getIntefaceurl());
                    objectMap.put("method", intefaceLinkDaos.getMethod());
                    objectMap.put("asserts", intefaceLinkDaos.getMethod());
                    objectMap.put("incodel", intefaceLinkDaos.getIncodel());
                    objectMap.put("unincloud", intefaceLinkDaos.getUnincloud());
                    objectMap.put("logins", intefaceLinkDaos.getLogins());
                    List<intefaceDetailParamesVo> intefaceDetailParamesVoList = intefaceLinkDaos.getIntefaceDetailParamesVoList();
                    List<Map<String, Object>> newparames = new ArrayList<>();
                    if (!intefaceDetailParamesVoList.isEmpty()) {
                        for (intefaceDetailParamesVo linkDaos : intefaceDetailParamesVoList) {
                            Map<String, Object> newparamesmap = new HashMap<>();
                            newparamesmap.put("types", linkDaos.getTypes());
                            newparamesmap.put("feilds", linkDaos.getFeilds());
                            newparamesmap.put("parames", linkDaos.getParames());
                            newparames.add(newparamesmap);
                        }
                    }

                    objectMap.put("intefaceDetailParamesVoList", newparames);
                    intefaceDetailDaosVoList.add(objectMap);
                }
            }
            map.put("intefaceLinkDaos", intefaceDetailDaosVoList);
            List<CommonParam> list=result.getCommonParamedetaiVoList();
            List<Map<String,Object>> paramelist=new ArrayList<>();
            if (!commonParamList.isEmpty()) {
                for (CommonParam commonParam:list){
                    Map<String,Object> newcommnparame=new HashMap<>();
                    newcommnparame.put("name",commonParam.getName());
                    newcommnparame.put("detail",commonParam.getDetail());
                    newcommnparame.put("sqlname",commonParam.getSqlname());
                    newcommnparame.put("typeid",commonParam.getTypeid());
                    newcommnparame.put("sqls",commonParam.getSqls());
                    paramelist.add(newcommnparame);
                }
            }
            map.put("commonParamedetaiVoList",paramelist);
            mapList.add(map);
        }
        reslutmap.put("code", code);
        reslutmap.put("msg", msg);
        reslutmap.put("data", data);
        return reslutmap;
    }

}
